#pragma once
#include<iostream>
#include<ctemplate/template.h>
#include<string>
#include<vector>
#include"oj_model.hpp"

namespace ns_View
{
    using namespace std;
    using namespace ns_Model;
    string template_path="./template_html/";
    class View
    {
    public:
    View()
    {}
    ~View()
    {}
     void AllExpandHtml(vector<Question>& questions,string* html)
    {
       string path=template_path+"all_question.html";
       ctemplate::TemplateDictionary root("allquestions");
       for(auto& q:questions)
       {
           ctemplate::TemplateDictionary* sub=root.AddSectionDictionary("questions");
           sub->SetValue("number",q.num);
           sub->SetValue("title",q.title);
           sub->SetValue("star",q.star);
       }
       //获取需要被渲染的网页
       ctemplate::Template* tql=ctemplate::Template::GetTemplate(path,ctemplate::DO_NOT_STRIP);
       //开始渲染网页
       tql->Expand(html,&root);
    }
    
     void OneExpandHtml(Question& q,string* html)
    {
      string path=template_path+"one_question.html";
      ctemplate::TemplateDictionary root("onequestion");
      root.SetValue("number",q.num);
      root.SetValue("title",q.title);
      root.SetValue("star",q.star);
      cout<<q.desc<<endl;
      root.SetValue("desc",q.desc);
      root.SetValue("pre_code",q.header);

      //获取需要被渲染的网页
      ctemplate::Template* tql=ctemplate::Template::GetTemplate(path,ctemplate::DO_NOT_STRIP);
      //渲染
      tql->Expand(html,&root);
    }

    };
}